/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rmidevmediateste;

import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 *
 * @author 710933
 */
public class ClienteImpl implements InterfaceComunicacaoRMI{


    public static void main (String[] args) {

        ClienteImpl c = new ClienteImpl();
        String host = (args.length < 1) ? "localhost" : args[0];
        String servico = "Servidor";
        Registry registry;
       try{

           //registry = LocateRegistry.getRegistry(host);
    	   registry = LocateRegistry.getRegistry();

           InterfaceComunicacaoRMI stubCliente = (InterfaceComunicacaoRMI) registry.lookup(servico);

           stubCliente.exibir("Ola Servidor, sou um Cliente!");

           System.out.println("Conectando ao servidor..");

           ServidorImpl stubServidor = new ServidorImpl();

           //ClienteImpl c1 = (ClienteImpl) stubCliente;
          // ClienteImpl c1 = new ClienteImpl();
           stubServidor.conectar(stubCliente);







        }catch(RemoteException r){
        	System.out.println("Remote exception no cliente!");
        }catch(NotBoundException n){
            n.printStackTrace();
        }catch (Exception e){
            System.out.println("Exception no cliente impl!");
            e.printStackTrace();
        }
    }


   public void exibir(String m) throws RemoteException {

       System.out.println(m);
}


}